import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class RefreshWidget extends StatelessWidget {

  final RefreshController controller;
  final Function onRefresh;
  final Function onLoading;
  final Widget child;
  final bool enablePulldown;

  const RefreshWidget({Key key, this.controller, this.enablePulldown = true, this.onRefresh, this.onLoading, this.child}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SmartRefresher(
        controller: controller,
        enablePullDown: this.enablePulldown,
        enablePullUp: true,
        onRefresh: onRefresh,
        onLoading: onLoading,
        header: MaterialClassicHeader(),
        footer: CustomFooter(
          height: 50,
          builder: (BuildContext context,LoadStatus mode){
            Widget body ;
            if(mode==LoadStatus.idle){
              body =  Text("上拉加载更多");
            }
            else if(mode==LoadStatus.loading){
              body =  CupertinoActivityIndicator();
            }
            // else if(mode == LoadStatus.failed){
            //   body = Text("Load Failed!Click retry!");
            // }
            else if(mode == LoadStatus.canLoading){
              body = Text("松开加载更多");
            }
            else{
              body = Text("没有更多数据了");
            }
            return Container(
              height: 55.0,
              child: Center(child:body),
            );
          },
        ),
        child: child,
    );
  }
}